//
//  Insure_tableViewCell.m
//  EggSteward
//
//  Created by 王道林 on 16/9/1.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "Insure_tableViewCell.h"
#import "BaseView.h"
#import "Masonry.h"

@interface Insure_tableViewCell ()<UITextFieldDelegate, UITextViewDelegate>
@property (nonatomic, strong) BaseView *View;
@property (nonatomic, strong) BaseView *ViewPlace;
@property (nonatomic, strong) BaseView *ViewDetail;
@property (nonatomic, strong) BaseView *Viewlayout;
@property (nonatomic, strong) UIView *viewLineO;
@property (nonatomic, strong) UIView *viewLineT;
@property (nonatomic, strong) UIView *viewLineS;
@property (nonatomic, strong) UIView *viewLineF;
@property (nonatomic, strong) UIView *viewLineW;
@end

@implementation Insure_tableViewCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubview];
        [self notification];
    }
    return self;
}

- (void)notification
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"day" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dayTime:) name:@"day" object:nil];
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    BOOL is = [userDefault boolForKey:@"night"];
    if (is == NO) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"day" object:nil userInfo:nil];
    }
}
- (void)dayTime:(NSNotification *)sender
{
    self.contentView.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
}

- (void)createSubview
{
    self.contentView.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
    // 背景view
    _View = [[BaseView alloc] init];
    _View.backgroundColor = [UIColor whiteColor];
    _View.layer.masksToBounds = YES;
    _View.layer.cornerRadius = 10;
    [self.contentView addSubview:_View];
    
    _ViewPlace = [[BaseView alloc] init];
    _ViewPlace.backgroundColor = [UIColor whiteColor];
    _ViewPlace.layer.masksToBounds = YES;
    _ViewPlace.layer.cornerRadius = 10;
    [self.contentView addSubview:_ViewPlace];
    
    _ViewDetail = [[BaseView alloc] init];
    _ViewDetail.backgroundColor = [UIColor whiteColor];
    _ViewDetail.layer.masksToBounds = YES;
    _ViewDetail.layer.cornerRadius = 10;
    [self.contentView addSubview:_ViewDetail];
    
    _Viewlayout = [[BaseView alloc] init];
    _Viewlayout.backgroundColor = [UIColor whiteColor];
    _Viewlayout.layer.masksToBounds = YES;
    _Viewlayout.layer.cornerRadius = 10;
    [self.contentView addSubview:_Viewlayout];
    // lable
    _lableName = [[BaseLabel alloc] init];
    _lableName.text = @"姓名";
    [_View addSubview:_lableName];
    
    _lablePhone = [[BaseLabel alloc] init];
    _lablePhone.text = @"手机号";
    [_View addSubview:_lablePhone];
    
    _lableChickenHouse = [[BaseLabel alloc] init];
    _lableChickenHouse.text = @"鸡场名称";
    [_View addSubview:_lableChickenHouse];
    
    _lableIDcard = [[BaseLabel alloc] init];
    _lableIDcard.text = @"身份证号";
    [_View addSubview:_lableIDcard];
    
    _lableBank = [[BaseLabel alloc] init];
    _lableBank.text = @"银行卡开户行";
    [_View addSubview:_lableBank];
    
    _lableBankNumber = [[BaseLabel alloc] init];
    _lableBankNumber.text = @"银行卡号";
    [_View addSubview:_lableBankNumber];


    // textfield
    _textFieldName = [[BaseTextField alloc] init];
    _textFieldName.delegate = self;
    _textFieldName.placeholder = @"您的姓名";
    [_View addSubview:_textFieldName];
    
    _textFieldPhone = [[BaseTextField alloc] init];
    _textFieldPhone.delegate = self;
    _textFieldPhone.placeholder = @"您的手机号";
    [_View addSubview:_textFieldPhone];
    
    _textFieldChickenHouse = [[BaseTextField alloc] init];
    _textFieldChickenHouse.delegate = self;
    _textFieldChickenHouse.placeholder = @"鸡场名称";
    [_View addSubview:_textFieldChickenHouse];
    
    _textFieldIDcard = [[BaseTextField alloc] init];
    _textFieldIDcard.delegate = self;
    _textFieldIDcard.placeholder = @"身份证号";
    [_View addSubview:_textFieldIDcard];
    
    _textFieldBank = [[BaseTextField alloc] init];
    _textFieldBank.delegate = self;
    _textFieldBank.placeholder = @"银行卡开户行";
    [_View addSubview:_textFieldBank];
    
    _textFieldBankNumber = [[BaseTextField alloc] init];
    _textFieldBankNumber.delegate = self;
    _textFieldBankNumber.placeholder = @"银行卡号";
    [_View addSubview:_textFieldBankNumber];
    // 横线
    _viewLineO = [[UIView alloc] init];
    _viewLineO.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
    [_View addSubview:_viewLineO];
    _viewLineT = [[UIView alloc] init];
    _viewLineT.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
    [_View addSubview:_viewLineT];
    _viewLineS = [[UIView alloc] init];
    _viewLineS.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
    [_View addSubview:_viewLineS];
    _viewLineF = [[UIView alloc] init];
    _viewLineF.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
    [_View addSubview:_viewLineF];
    _viewLineW = [[UIView alloc] init];
    _viewLineW.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
    [_View addSubview:_viewLineW];
    
    // textView
    _textViewPlace = [[BaseTextView alloc] init];
    _textViewPlace.delegate = self;
    _textViewPlace.text = @"鸡场位置,详细地址:";
    [_ViewPlace addSubview:_textViewPlace];
    
    _textViewDetail = [[BaseTextView alloc] init];
    _textViewDetail.delegate = self;
    _textViewDetail.text = @"鸡舍内部详细信息描述:";
    [_ViewDetail addSubview:_textViewDetail];
    
    _textViewlayout = [[BaseTextView alloc] init];
    _textViewlayout.delegate = self;
    _textViewlayout.text = @"鸡舍平面布局描述";
    [_Viewlayout addSubview:_textViewlayout];


    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    // 背景view的约束
    [_View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).mas_offset(20);
        make.right.mas_equalTo(self.contentView.mas_right).mas_offset(-20);
        make.top.mas_equalTo(self.contentView.mas_top);
        make.height.mas_equalTo(self.contentView.mas_height).multipliedBy(0.4);
    }];
    
    [_ViewPlace mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).mas_offset(20);
        make.right.mas_equalTo(self.contentView.mas_right).mas_offset(-20);
        make.top.mas_equalTo(_View.mas_bottom).mas_offset(30);
        make.height.mas_equalTo(self.contentView.mas_height).multipliedBy(0.15);
    }];

    [_ViewDetail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).mas_offset(20);
        make.right.mas_equalTo(self.contentView.mas_right).mas_offset(-20);
        make.top.mas_equalTo(_ViewPlace.mas_bottom).mas_offset(30);
        make.height.mas_equalTo(self.contentView.mas_height).multipliedBy(0.15);
    }];
    
    [_Viewlayout mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).mas_offset(20);
        make.right.mas_equalTo(self.contentView.mas_right).mas_offset(-20);
        make.top.mas_equalTo(_ViewDetail.mas_bottom).mas_offset(30);
        make.height.mas_equalTo(self.contentView.mas_height).multipliedBy(0.15);
    }];
    // lable 的约束
    [_lableName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(20);
        make.top.mas_equalTo(_View.mas_top);
        make.height.mas_equalTo(_View.mas_height).multipliedBy(0.16666);
        make.width.mas_equalTo(_View.mas_width).multipliedBy(0.4);
    }];
    [_lableChickenHouse mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(20);
        make.top.mas_equalTo(_lableName.mas_bottom);
        make.height.mas_equalTo(_View.mas_height).multipliedBy(0.16666);
        make.width.mas_equalTo(_View.mas_width).multipliedBy(0.4);
    }];
    [_lablePhone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(20);
        make.top.mas_equalTo(_lableChickenHouse.mas_bottom);
        make.height.mas_equalTo(_View.mas_height).multipliedBy(0.16666);
        make.width.mas_equalTo(_View.mas_width).multipliedBy(0.4);
    }];
    
    [_lableIDcard mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(20);
        make.top.mas_equalTo(_lablePhone.mas_bottom);
        make.height.mas_equalTo(_View.mas_height).multipliedBy(0.16666);
        make.width.mas_equalTo(_View.mas_width).multipliedBy(0.4);
    }];
    [_lableBank mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(20);
        make.top.mas_equalTo(_lableIDcard.mas_bottom);
        make.height.mas_equalTo(_View.mas_height).multipliedBy(0.16666);
        make.width.mas_equalTo(_View.mas_width).multipliedBy(0.4);
    }];
    [_lableBankNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(20);
        make.top.mas_equalTo(_lableBank.mas_bottom);
        make.height.mas_equalTo(_View.mas_height).multipliedBy(0.16666);
        make.width.mas_equalTo(_View.mas_width).multipliedBy(0.4);
    }];
    // textfield 的约束
    [_textFieldName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_lableName.mas_right).mas_offset(10);
        make.top.mas_equalTo(_View.mas_top);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(_lableName.mas_height);
    }];
    [_textFieldChickenHouse mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_lableChickenHouse.mas_right).mas_offset(10);
        make.top.mas_equalTo(_textFieldName.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(_lableName.mas_height);
    }];
    [_textFieldPhone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_lablePhone.mas_right).mas_offset(10);
        make.top.mas_equalTo(_textFieldChickenHouse.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(_lableName.mas_height);
    }];
    [_textFieldIDcard mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_lablePhone.mas_right).mas_offset(10);
        make.top.mas_equalTo(_textFieldPhone.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(_lableName.mas_height);
    }];
    [_textFieldBank mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_lableIDcard.mas_right).mas_offset(10);
        make.top.mas_equalTo(_textFieldIDcard.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(_lableName.mas_height);
    }];
    [_textFieldBankNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_lableBank.mas_right).mas_offset(10);
        make.top.mas_equalTo(_textFieldBank.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(_lableName.mas_height);
    }];
    // 横条
    [_viewLineO mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(10);
        make.top.mas_equalTo(_textFieldName.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(1);
    }];
    [_viewLineT mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(10);
        make.top.mas_equalTo(_textFieldChickenHouse.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(1);
    }];
    [_viewLineS mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(10);
        make.top.mas_equalTo(_textFieldPhone.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(1);
    }];
    [_viewLineF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(10);
        make.top.mas_equalTo(_textFieldIDcard.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(1);
    }];
    [_viewLineW mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(10);
        make.top.mas_equalTo(_textFieldBank.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(1);
    }];
    
    // textview的约束
    [_textViewPlace mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_ViewPlace.mas_left).mas_offset(15);
        make.right.mas_equalTo(_ViewPlace.mas_right).mas_offset(-15);
        make.top.mas_equalTo(_ViewPlace.mas_top).mas_offset(10);
        make.bottom.mas_equalTo(_ViewPlace.mas_bottom).mas_offset(-10);
    }];

    [_textViewDetail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_ViewDetail.mas_left).mas_offset(15);
        make.right.mas_equalTo(_ViewDetail.mas_right).mas_offset(-15);
        make.top.mas_equalTo(_ViewDetail.mas_top).mas_offset(10);
        make.bottom.mas_equalTo(_ViewDetail.mas_bottom).mas_offset(-10);
    }];
    
    [_textViewlayout mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_Viewlayout.mas_left).mas_offset(15);
        make.right.mas_equalTo(_Viewlayout.mas_right).mas_offset(-15);
        make.top.mas_equalTo(_Viewlayout.mas_top).mas_offset(10);
        make.bottom.mas_equalTo(_Viewlayout.mas_bottom).mas_offset(-10);
    }];
}
#pragma mark -textfield协议
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    self.blockBegenText();
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    self.blockEndText();
}

- (void)textViewDidBeginEditing:(UITextView *)textView
{
    self.blockBegenText();
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
    self.blockEndText();
}


@end
